package com.jams.goodox.activity.home;

import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.utils.StyleUtil;
import com.jams.goodox.utils.ToastUtil;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/10/8.
 */

public class ChooseWuliuActivity extends BaseActivity {
    @Bind(R.id.tx_zfl)
    TextView txZfl;
    @Bind(R.id.tx_wx)
    TextView txWx;
    @Bind(R.id.tx_yj)
    TextView txYj;
    @Bind(R.id.tx_sure_pay)
    TextView txSurePay;
    @Bind(R.id.tx_zs)
    TextView txZs;
    @Bind(R.id.linear_logistic)
    LinearLayout linear_logistic;
    @Bind(R.id.edit_other)
    EditText edit_other;

    private String logistic="德邦快递";

    @Override
    protected int getLayoutId() {
        return R.layout.choose_pay_way_activity;
    }

    @Override
    protected void init() {
        StyleUtil.titleBackKey(this, "选择物流方式");
        txZs.setText("注：公司默认支持德邦快递，德邦物流，所有物流一律货到付款");
        txZfl.setText("德邦快递");
        txWx.setText("德邦物流");
        txYj.setText("其他物流");
    }

    @OnClick({R.id.tx_zfl, R.id.tx_wx, R.id.tx_yj, R.id.tx_sure_pay})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tx_zfl:
                onChoosePay(0);
                linear_logistic.setVisibility(View.GONE);
                logistic="德邦快递";
                break;
            case R.id.tx_wx:
                onChoosePay(1);
                linear_logistic.setVisibility(View.GONE);
                logistic="德邦物流";
                break;
            case R.id.tx_yj:
                onChoosePay(2);
                linear_logistic.setVisibility(View.VISIBLE);
                break;
            case R.id.tx_sure_pay:
                if(position==2){
                    logistic=edit_other.getText().toString().trim();
                    if(TextUtils.isEmpty(logistic)){
                        ToastUtil.show("请填写物流方式");
                        return;
                    }
                }
                Intent intent=new Intent();
                intent.putExtra("logistic",logistic);
                setResult(RESULT_OK,intent);
                finish();
                break;
        }
    }

    private int position;
    private void onChoosePay(int position){
        this.position=position;
        txZfl.setTextColor(ContextCompat.getColor(this,position==0?R.color.font_color_red:R.color.font_color_black));
        txWx.setTextColor(ContextCompat.getColor(this,position==1?R.color.font_color_red:R.color.font_color_black));
        txYj.setTextColor(ContextCompat.getColor(this,position==2?R.color.font_color_red:R.color.font_color_black));
        txZfl.setBackground(ContextCompat.getDrawable(this,position==0?R.drawable.bg_cancel_white_red:R.drawable.bg_cancel_white_black));
        txWx.setBackground(ContextCompat.getDrawable(this,position==1?R.drawable.bg_cancel_white_red:R.drawable.bg_cancel_white_black));
        txYj.setBackground(ContextCompat.getDrawable(this,position==2?R.drawable.bg_cancel_white_red:R.drawable.bg_cancel_white_black));
    }
}
